package com.web;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.entity.Employee;
import com.service.EmployeeService;

public class Login extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		if ("POST".equals(request.getMethod())) {
			String username=request.getParameter("username");
			String password=request.getParameter("password");
			
			EmployeeService service=new EmployeeService();
			Employee employee=service.login(username,password);
			if(employee!=null){
				request.getSession().setAttribute("employee", employee);
				request.getRequestDispatcher("projectlist.jspx").forward(request, response);
			}else{
				request.setAttribute("msg", "login_fail");
				request.getRequestDispatcher("WEB-INF/views/login.jsp").forward(request, response);
			}
		}else {
			request.getRequestDispatcher("projectlist.jspx").forward(request, response);
		}
		
		
	}
	

}
